import keyWordConfig from './config';
import accounting from 'accounting';
export default (trade, record, key, type) => {
  if (trade) {
    if (type == 'number') {
      let keys = keyWordConfig[record.type][key];
      if (keys == undefined) {
        return '';
      }
      if (trade[keys] === null || trade[keys] === undefined) {
        return '--';
      } else {
        if (isNaN(trade[keys])) {
          return trade[keys];
        } else {
          return Number(trade[keys]).toFixed(2);
        }
      }
    } else if (type == 'money') {
      let keys = keyWordConfig[record.type][key];

      if (keys == undefined) {
        return '';
      }
      let datas = trade[keys];
      if (record.type === '13') {
        datas = trade.pledgeVo[0].transactionAmount;
      }
      if (datas === null || datas === undefined) {
        return '--';
      } else {
        if (isNaN(datas)) {
          return datas;
        } else {
          return accounting.formatNumber(Number(datas), 2);
        }
      }
    } else if (type == 'moneys') {
      let keys = keyWordConfig[record.type][key];

      if (keys == undefined) {
        return '';
      }
      let datas = trade[keys];
      if (record.type === '13') {
        datas = trade.pledgeVo[0].transactionAmount;
      }
      if (datas === null || datas === undefined) {
        return '--';
      } else {
        if (isNaN(datas)) {
          return datas;
        } else {
          return accounting.formatNumber(Number(datas), 4);
        }
      }
    } else if (type == 'rate') {
      let keys = keyWordConfig[record.type][key];
      if (keys == undefined) {
        return '';
      }
      if (trade[keys] === null || trade[keys] === undefined) {
        return '--';
      } else {
        if (isNaN(trade[keys])) {
          return trade[keys];
        } else {
          if (record.type == 6) {
            return Number(trade[keys] * 100).toFixed(2);
          }
          return Number(trade[keys]).toFixed(2);
        }
      }
    } else {
      let keys = keyWordConfig[record.type][key];
      if (keys == undefined) {
        return '';
      }
      if (trade[keys] === null || trade[keys] === undefined) {
        return '--';
      } else {
        return trade[keys];
      }
    }
  } else {
    return '';
  }
};
